<?php

namespace Kunfeng\Dify\Model\Workflow;

/**
 * 工作流运行状态响应模型
 */
class WorkflowRunStatusResponse
{
    private $taskId;
    private $status;
    private $data;
    private $error;
    private $elapsedTime;

    public function __construct(array $data)
    {
        $this->taskId = $data['task_id'] ?? '';
        $this->status = $data['status'] ?? '';
        $this->data = $data['data'] ?? null;
        $this->error = $data['error'] ?? null;
        $this->elapsedTime = $data['elapsed_time'] ?? 0;
    }

    /**
     * 从数组创建
     */
    public static function fromArray(array $data): self
    {
        return new self($data);
    }

    // Getters
    public function getTaskId(): string
    {
        return $this->taskId;
    }

    public function getStatus(): string
    {
        return $this->status;
    }

    public function getData(): ?array
    {
        return $this->data;
    }

    public function getError(): ?string
    {
        return $this->error;
    }

    public function getElapsedTime(): int
    {
        return $this->elapsedTime;
    }

    /**
     * 判断是否完成
     */
    public function isCompleted(): bool
    {
        return $this->status === 'completed';
    }

    /**
     * 判断是否失败
     */
    public function isFailed(): bool
    {
        return $this->status === 'failed';
    }

    /**
     * 判断是否运行中
     */
    public function isRunning(): bool
    {
        return $this->status === 'running';
    }
}